/*
2020-10-12 周一 制作
*/
#include <stdio.h>
#include <ctime>
int main()
{
	//int isLeapyear(int year);
	
	int getYear();
	int getMonth();
	int getDay();
	
	int Years(int year,int month,int day);
	int birth_year,birth_month,birth_day;
	int cur_year,cur_month,cur_day;
	int livedays = 0;
	int workdays = 0;
	int year,month,day;
	printf("请输入你的出生年月日如(2000-1-1):");
	scanf("%d-%d-%d",&birth_year,&birth_month,&birth_day);
	printf("你输入的生日是:%d-%d-%d\n",birth_year,birth_month,birth_day);
	
    cur_year = getYear();
	cur_month = getMonth();
	cur_day = getDay();
	printf("今天是:%d-%d-%d\n",cur_year,cur_month,cur_day);
	livedays = Years(cur_year,cur_month,cur_day)-Years(birth_year,birth_month,birth_day);
	workdays = Years(cur_year,cur_month,cur_day)-Years(birth_year+7,birth_month,birth_day);

//	printf("今天是:2020-10-12\n");
//	livedays = Years(2020,10,12)-Years(birth_year,birth_month,birth_day);
//	workdays = Years(2020,10,12)-Years(birth_year+7,birth_month,birth_day);

	printf("你从出生到现在已经过了: %d 天\n",livedays);
	printf("你从出生到现在已经过了: %d 小时\n",livedays*24);
	printf("你从出生到现在已经过了: %d 分钟\n",livedays*24*60);
	printf("你从出生到现在已经过了: %d 秒\n",livedays*24*60*60);
	printf("你从7岁开始三天打渔两天晒网已经: %d 天\n",workdays);
	printf("今天你是在: ");
	if(workdays%5==1||workdays%5==2||workdays%5==3)
	{
		printf("打渔!\n");
	}
	else
	{
		printf("晒网!\n");
	}

return 0;
}

int isLeapyear(int year)
{
	if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
	{
		return 1;
	}
	return 0;
}

int Years(int year,int month,int day)
{
	int days=0;
	int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
	for(int i=1900;i<year;i++)
	{
		if(isLeapyear(i)==1)
		{
			days+=366;
		}else
		{
			days+=365;
		}
	}
	if(isLeapyear(year)==1)
	{
		a[1]=29;
	}
	for (int i=0;i<month-1;i++){
		days += a[i];
	}
	days = days + day;
	return days;
}


int getYear(){
	time_t now = time(0);
	tm *ltm = localtime(&now);
	return ltm->tm_year + 1900;
}

int getMonth(){
	time_t now = time(0);
	tm *ltm = localtime(&now);
	return ltm->tm_mon + 1;
}
int getDay(){
	time_t now = time(0);
	tm *ltm = localtime(&now);
	return ltm->tm_mday;
}
